<?php

namespace app\command;

use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
/**
 * Class MemberLogOff
 * 账号注销
 * @package app\command
 */
class MemberLogOff extends Command
{
    protected function configure()
    {
        // 指令配置
        $this->setName('MemberLogOff');
        // 设置参数
        
    }

    protected function execute(Input $input, Output $output)
    {
        if (!funCheckThread('MemberLogOff')) return;
    	$output->writeln('开始查询');
        $map['status'] = 1;
        $map['audit_status'] = 2;
        $rows = Db::name('member_log_off')->where($map)->select();
        $output->writeln('查询完成，执行中');
        Db::startTrans();
        try {
            foreach ($rows as $k=>$v){
                if($v['log_off_time'] < time() && $v['audit_status'] == 2){
                    $save = array(
                        'username'  => '',
                        'password'  => '',
                        'phone'     => '',
                        'realname'  => '',
                        'idcard'    => '',
                        'age_status'=> 0,
                        'log_off'   => 2,
                        'mark'      => 0
                    );
                    Db::name('member')->where('id',$v['member_id'])->update($save);
                    Db::name('member_log_off')->where('id',$v['id'])->update(['status'=>2]);
                    $output->writeln($v['member_account'].'：完成注销');
                }
            }
            Db::commit();
        }catch (\Exception $e){
            Db::rollback();
            $output->writeln($e->getMessage());
        }
        $output->writeln('本次执行完成');
    }
}
